package com.haq.housesystem.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.haq.housesystem.bean.Admins;

import com.haq.housesystem.dao.AdminsDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.haq.housesystem.service.AdminsService;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class AdminsServiceImpl implements AdminsService {
    @Autowired
    AdminsDao adminsDao;

    public void insert(Admins admins) {
        adminsDao.insert(admins);

    }

    public void update(Admins admins) {
        adminsDao.update(admins);

    }

    public void delete(String adminsId) {
        adminsDao.delete(adminsId);

    }

    public void deleteByIds(String[] adminsIds) {
        adminsDao.deleteByIds(adminsIds);

    }

    public List<Admins> selectAll() {
        List<Admins> list = adminsDao.selectAll();
        return list;
    }

    public Admins selectById(String adminsId) {
        Admins admins = adminsDao.selectById(adminsId);
        return admins;
    }

    public List<Admins> selectByNameState(String adminsName, int adminsState) {
        Map map=new HashMap();
        map.put("adminsName", adminsName);
        map.put("adminsState", adminsState);
        List<Admins> list = adminsDao.selectByNameState(map);
        return list;
    }

    @Override
    public int getNumer() {
        return 0;
    }

    public int getNumber() {
        int number = adminsDao.getNumber();
        return number;
    }

    public PageInfo<Admins> selectAllByPageInfo(int curPage, int size) {
        //设置分页数据  参数1 当前页码   参数2 每页显示条数
        PageHelper.startPage(curPage, size);
        List<Admins> list=adminsDao.selectAll();
        //list数据设置导PageInfo中
        PageInfo<Admins> pageInfo=new PageInfo<Admins>(list);
        return pageInfo;
    }

    public PageInfo<Admins> selectByNameStateByPageInfo(int curPage, int size, String adminsName, int adminsState) {
        PageHelper.startPage(curPage, size);
        Map map=new HashMap();
        map.put("adminsName", adminsName);
        map.put("adminsState", adminsState);
        List<Admins> list = adminsDao.selectByNameState(map);
        PageInfo<Admins> pageInfo=new PageInfo<Admins>(list);
        return pageInfo;
    }
}
